package cn.itcast.myapplication.viewemodel;

import androidx.lifecycle.MutableLiveData;

import androidx.lifecycle.ViewModel;

public class ViewModelWithLiveData extends ViewModel {


    /**
      相当于是一个容器
    */
    private MutableLiveData<Integer> LikedNumbfer;


    public MutableLiveData<Integer> getLikedNumbfer() {

        //判断是否有创建，没有则创建一个并且初始化为零
        if (LikedNumbfer==null){

            LikedNumbfer=new MutableLiveData<>();

            LikedNumbfer.setValue(0);

        }

        return LikedNumbfer;

    }


    //自身加n
    public void addLikedNumber(int n){

        LikedNumbfer.setValue(LikedNumbfer.getValue()+n);

    }


}
